package com.xcc.commandpattern;

import com.xcc.commandpattern.demo01.*;
import com.xcc.commandpattern.demo01.GarageDoor;
import com.xcc.commandpattern.demo01.Light;
import com.xcc.commandpattern.demo01.LightOnCommand;
import com.xcc.commandpattern.demo02.*;

/**
 * @Author xiechuang
 * @Date 2022/9/7
 */
public class Demo {

    public static void main(String[] args) {
        SimpleRemoteControl remote = new SimpleRemoteControl();

        Light light = new Light();
        LightOnCommand lightOn = new LightOnCommand(light);
        remote.setCommand(lightOn);
        remote.buttonWasPressed();

        GarageDoor garageDoor = new GarageDoor();
        GarageDoorOpenCommand garageDoorOpenCommand = new GarageDoorOpenCommand(garageDoor);
        remote.setCommand(garageDoorOpenCommand);
        remote.buttonWasPressed();

        RemoteControl remoteControl = new RemoteControl();
        com.xcc.commandpattern.demo02.Light livingRoomLight = new com.xcc.commandpattern.demo02.Light("Living Room");
        com.xcc.commandpattern.demo02.Light kitchenLight = new com.xcc.commandpattern.demo02.Light("Kitchen");
        CeilingFan ceilingFan = new CeilingFan("Living Room");
        com.xcc.commandpattern.demo02.GarageDoor garageDoor2 = new com.xcc.commandpattern.demo02.GarageDoor("");
        Stereo stereo = new Stereo("Living Room");

        com.xcc.commandpattern.demo02.LightOnCommand livingRoomLightOn = new com.xcc.commandpattern.demo02.LightOnCommand(livingRoomLight);
        com.xcc.commandpattern.demo02.LightOffCommand livingRoomLightOff = new com.xcc.commandpattern.demo02.LightOffCommand(livingRoomLight);
        com.xcc.commandpattern.demo02.LightOnCommand kitchenLightOn = new com.xcc.commandpattern.demo02.LightOnCommand(kitchenLight);
        com.xcc.commandpattern.demo02.LightOffCommand kitchenLightOff = new com.xcc.commandpattern.demo02.LightOffCommand(kitchenLight);

        CeilingFanOnCommand ceilingFanOn = new CeilingFanOnCommand(ceilingFan);
        CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan);

        GarageDoorUpCommand garageDoorUp = new GarageDoorUpCommand(garageDoor2);
        GarageDoorDownCommand garageDoorDown = new GarageDoorDownCommand(garageDoor2);

        StereoOnWithCDCommand stereoOnWithCD = new StereoOnWithCDCommand(stereo);
        StereoOffCommand stereoOff = new StereoOffCommand(stereo);

        remoteControl.setCommand(0, livingRoomLightOn, livingRoomLightOff);
        remoteControl.setCommand(1, kitchenLightOn, kitchenLightOff);
        remoteControl.setCommand(2, ceilingFanOn, ceilingFanOff);
        remoteControl.setCommand(3, garageDoorUp, garageDoorDown);
        remoteControl.setCommand(4, stereoOnWithCD, stereoOff);

        System.out.println(remoteControl);

        remoteControl.onButtonWasPushed(0);
        remoteControl.offButtonWasPushed(0);
        remoteControl.onButtonWasPushed(1);
        remoteControl.offButtonWasPushed(1);
        remoteControl.onButtonWasPushed(2);
        remoteControl.offButtonWasPushed(2);
        remoteControl.onButtonWasPushed(3);
        remoteControl.offButtonWasPushed(3);
        remoteControl.onButtonWasPushed(4);
        remoteControl.offButtonWasPushed(4);

        RemoteControlWithUndo remoteControlWithUndo = new RemoteControlWithUndo();
        com.xcc.commandpattern.demo02.Light livingRoomLight3 = new com.xcc.commandpattern.demo02.Light("Living Room");
        com.xcc.commandpattern.demo02.LightOnCommand livingRoomLightOn3 = new com.xcc.commandpattern.demo02.LightOnCommand(livingRoomLight3);
        com.xcc.commandpattern.demo02.LightOffCommand livingRoomLightOff3 = new com.xcc.commandpattern.demo02.LightOffCommand(livingRoomLight3);

        remoteControlWithUndo.setCommand(0, livingRoomLightOn3, livingRoomLightOff3);

        remoteControlWithUndo.onButtonWasPushed(0);
        remoteControlWithUndo.offButtonWasPushed(0);
        System.out.println(remoteControlWithUndo);
        remoteControlWithUndo.undoButtonWasPushed();
        remoteControlWithUndo.offButtonWasPushed(0);
        remoteControlWithUndo.onButtonWasPushed(0);
        System.out.println(remoteControlWithUndo);
        remoteControlWithUndo.undoButtonWasPushed();
    }

}
